﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutForEUI.cshtml";
    var listColumns = ViewBag.Columns as List<SGArchiveSystem7x.Models.CColumnsModel>;
}
<table id="LogLogin_Index_grid" class="easyui-datagrid" style="width:100%;" title="登录日志" data-options="
       rownumbers:true,
       singleSelect:true,
       autoRowHeight:false,
       pagination:true,
       fitColumns:true,
       fit:true,
       striped:true,
       checkOnSelect:false,
       selectOnCheck:false,
       toolbar:'#LogLogin_Index_tb',
       collapsible:false,
       pageSize: @SGArchiveSystem7x.Models.CCommonsModels.PageSize,
       pageList:[10,15,20]">
    <thead frozen="true">
        <tr>
            @{foreach (var c in listColumns)
                {
                    if (c.Frozen)
                    {
                        <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                    }

                }
            }
        </tr>
    </thead>
    <thead>
        <tr>
            @{foreach (var c in listColumns)
                {
                    if (!c.Frozen)
                    {
                        <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                    }

                }
            }
        </tr>
    </thead>
</table>
<div id="LogLogin_Index_tb" style="padding:2px 5px;">
    <input type="text" class="easyui-textbox" label="用户名:" labelwidth="50px" style="width:180px" id="LogLogin_Index_txtName" />
    <input type="text" class="easyui-datebox"  data-options="editable:false" label="起始时间:" labelwidth="80px" style="width:180px" id="LogLogin_Index_txtSTime" />
    <input type="text" class="easyui-datebox" data-options="editable:false" label="结束时间:" labelwidth="80px" style="width:180px" id="LogLogin_Index_txtETime" />
    <a href="javascript:void(0);" id="LogLogin_Index_btnQuery" class="easyui-linkbutton button-blue" iconCls="icon-search" onclick="Search()" style="width:110px;height:30px;">查询</a>
    <a href="javascript:void(0);" id="LogLogin_Index_btnDownload" class="easyui-linkbutton button-blue" iconCls="icon-redo" onclick="Download()" style="width:110px;height:30px;">导出xls</a>
</div>
<script>
    $(document).ready(function () {
        $('#LogLogin_Index_grid').datagrid({
            url: '/LogLogin/Get_ajaxLogLoginList?uname=&stime=&etime=',
            singleSelect: true,
            method: 'post',
            onLoadSuccess: function (data) {
                $('.pagination-page-list').hide();
            }
        });

        InitPagenation();
    });

    ///初始化分页
    function InitPagenation() {
        //设置分页控件
        var p = $('#LogLogin_Index_grid').datagrid('getPager');
        $(p).pagination({
            onSelectPage: function (pageNumber, pageSize) {
                SearchPager(pageNumber, pageSize);
            }
        });
    }

    function Search() 
    {
        var uname = $('#LogLogin_Index_txtName').val();
        var stime = $('#LogLogin_Index_txtSTime').datebox('getValue');
        var etime = $('#LogLogin_Index_txtETime').datebox('getValue');
        $('#LogLogin_Index_grid').datagrid('options').url = '/LogLogin/Get_ajaxLogLoginList?uname=' + uname + '&stime=' + stime + '&etime=' + etime ;
        $('#LogLogin_Index_grid').datagrid('load');
        $('#LogLogin_Index_grid').datagrid('options').pageNumber = 1;
    }

    function SearchPager(num, size) {

        $('#LogLogin_Index_grid').datagrid('options').url = '/LogLogin/Get_ajaxLogLoginListPager?num=' + num +
            '&size=' + size;
        $('#LogLogin_Index_grid').datagrid('reload');
        $('#LogLogin_Index_grid').datagrid('options').pageNumber = num;
        $('#LogLogin_Index_grid').datagrid('options').pageSize = size;
    }

    function Download()
    {
        var grid = $('#LogLogin_Index_grid');
        var options = grid.datagrid('getPager').data("pagination").options;
        var total = options.total;
        //var total = 101;
        if (total > 100)
        {
            $.messager.confirm('提示', '数据量过多，是否仍然需要导出？', function (r) {
                if (r) {
                    $.ajax({
                        url: "/LogLogin/DownLoadxls",
                        dataType: "text",
                        type: "post",
                        success: function (data) {
                            window.open(data);
                        }
                    });
                }
            });
        }
        else
        {
            $.ajax({
                url: "/LogLogin/DownLoadxls",
                dataType: "text",
                type: "post",
                success: function (data) {
                   // alert(data);
                    window.open(data);
                }
            });
        }      
    }
    function formatDATE(value, row) {
        if (value != null) {
            var time = new Date(parseInt(value.substr(6, 19)))//.toLocaleDateString();//13
            return time.getFullYear() + "-" + (time.getMonth() + 1) + "-" + time.getDate() + " " + time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();
        }
        else {
            return "";
        }
    }
    function formatType(value, row) {
        if (value == '0')
            return "<span>普通登录</span>";
        else
            return "<span>AD域登录</span>"
    }
    function formatISIP(value, row) {
        if (value == '0')
            return "<span>否</span>";
        else
            return "<span>是</span>"
    }
</script>
